package com.michaelbulava.TFS.ui.dialogs.connect;

import com.intellij.openapi.project.Project;
import com.michaelbulava.TFS.Messages;
import com.michaelbulava.TFS.ui.controls.connect.ServerListControl;
import com.michaelbulava.TFS.ui.dialogs.BaseDialog;
import com.microsoft.tfs.core.TFSConnection;
import com.microsoft.tfs.core.util.serverlist.ServerListConfigurationEntry;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;

/**
 * Created by mbulava on 6/19/2015.
 */
public class ServerListDialog extends BaseDialog {

    private ServerListConfigurationEntry lastAddedServerListEntry;

    private ServerListControl serverListControl;

    public ServerListDialog(@NotNull Component parent) {
        super(parent);
    }

    public ServerListDialog(@Nullable Project project) {
        super(project);
    }

    @Override
    protected JComponent createControl() {
        if (serverListControl == null) {

            serverListControl = new ServerListControl();
            serverListControl.setServerListConfigurationEntryAddedListener(new ServerListControl.ServerListConfigurationEntryAddedListener() {
                @Override
                public void onServerListConfigurationEntryAdded(ServerListConfigurationEntry newEntry) {
                    lastAddedServerListEntry = newEntry;
                }
            });
        }
        return serverListControl;
    }

    @Override
    protected String dialogTitle() {
        return Messages.getString("ServerListDialog.Title");
    }

    public ServerListConfigurationEntry getLastAddedServerListEntry(){
        return lastAddedServerListEntry;
    }

    public TFSConnection getLastAddedConnection(){
        //TODO get this value from the control once it's created.
        return null;
    }
}